X10_PATH=/opt/x10-2.2.0.1/bin

MRE_PATH=./MREngine

# environment variables
X10_NTHREADS := 24

# Application Parameters 
WC_INPUT_PATH=./word_10MB.txt
NUM_ASYNCS=4 8 16 24
NUM_TRIALS=3
DICT_LOC=./dict
ID_INPUT_PATH=./input/
NUM_INPUT_FILE=300

all: WordCount InvertDoc

wordcount: functest_wc perftest_wc
invertdoc: functest_id perftest_id

functest_all: wordcount.func.out invertdoc.func.out
perftest_all: wordcount.perf.out invertdoc.perf.out

functest_wc: wordcount.func.out
perftest_wc: wordcount.perf.out

functest_id: invertdoc.func.out
perftest_id: invertdoc.perf.out

wordcount.func.out: $(NUM_ASYNCS:%=wordcount.func.%.buildandrun)
wordcount.func.%.buildandrun: WordCount 
	$(X10_PATH)/x10 WordCount $(WC_INPUT_PATH) $* $(NUM_TRIALS) func > wordcount.func.$*.out
	@echo "Find your results in wordcount.func.$*.out"
	@echo " "
	@echo " "

wordcount.perf.out: $(NUM_ASYNCS:%=wordcount.perf.%.buildandrun)
wordcount.perf.%.buildandrun: WordCount
	srun $(X10_PATH)/x10 WordCount $(WC_INPUT_PATH) $* $(NUM_TRIALS) perf > wordcount.perf.$*.out
	@echo "Dumping contents of wordcount.perf.out ... "
	@grep "" wordcount.perf.$*.out
	@echo "Find your results in wordcount.perf.$*.out"
	@echo " "
	@echo " "

invertdoc.func.out: $(NUM_ASYNCS:%=invertdoc.func.%.buildandrun)
invertdoc.func.%.buildandrun: InvertDoc
	$(X10_PATH)/x10 InvertDoc $* $(NUM_TRIALS) func $(DICT_LOC) $(ID_INPUT_PATH) $(NUM_INPUT_FILE) > invertdoc.func.$*.out
	@echo "Find your results in invertdoc.func.$*.out"
	@echo " "
	@echo " "

invertdoc.perf.out: $(NUM_ASYNCS:%=invertdoc.perf.%.buildandrun)
invertdoc.perf.%.buildandrun: InvertDoc
	srun $(X10_PATH)/x10 InvertDoc $* $(NUM_TRIALS) perf $(DICT_LOC) $(ID_INPUT_PATH) $(NUM_INPUT_FILE) > invertdoc.perf.$*.out
	@echo "Dumping contents of invertdoc.perf.out ..."
	@grep "" invertdoc.perf.$*.out
	@echo "Find your results in invertdoc.perf.$*.out"
	@echo " "
	@echo " "

WordCount: WordCount.class
WordCount.class: WordCount.x10 $(MRE_PATH)/MapReduceEngineSeq.x10 \
			$(MRE_PATH)/MapReduceEnginePar.x10 $(MRE_PATH)/MREEntry.x10
	$(X10_PATH)/x10c WordCount.x10 $(MRE_PATH)/MapReduceEngineSeq.x10 $(MRE_PATH)/MREData.x10 \
	$(MRE_PATH)/MapReduceEnginePar.x10 $(MRE_PATH)/MREEntry.x10

InvertDoc: InvertDoc.class
InvertDoc.class: InvertDoc.x10 $(MRE_PATH)/MapReduceEngineSeq.x10 \
			$(MRE_PATH)/MapReduceEnginePar.x10 $(MRE_PATH)/MREEntry.x10
	$(X10_PATH)/x10c InvertDoc.x10 $(MRE_PATH)/MapReduceEngineSeq.x10 $(MRE_PATH)/MREData.x10 \
    $(MRE_PATH)/MapReduceEnginePar.x10 $(MRE_PATH)/MREEntry.x10
	

.PHONY:
clean:
	rm -f *.out *.java *.class *.log 
	cd $(MRE_PATH); rm -f *.out *.java *.class *.log *~ 


$(MRE_PATH)/MapReduceEngineSeq.x10: $(MRE_PATH)/MREData.x10 $(MRE_PATH)/MREEntry.x10
$(MRE_PATH)/MapReduceEnginePar.x10: $(MRE_PATH)/MREData.x10 $(MRE_PATH)/MREEntry.x10
WordCount.x10: $(MRE_PATH)/MapReduceEngineSeq.x10 $(MRE_PATH)/MapReduceEnginePar.x10 \
				$(MRE_PATH)/MREData.x10 $(MRE_PATH)/MREEntry.x10
InvertDoc.x10: $(MRE_PATH)/MapReduceEngineSeq.x10 $(MRE_PATH)/MapReduceEnginePar.x10 \
				$(MRE_PATH)/MREData.x10 $(MRE_PATH)/MREEntry.x10

